package com.huawei.hianalytics.f.g;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import com.tencent.mm.opensdk.constants.ConstantsAPI.AppSupportContentFlag;

public class b {
    private static b a = new b();
    private long b = 0;
    private boolean c = false;
    private SharedPreferences d = h.d(com.huawei.hianalytics.a.b.n(), "backup_event");

    private b() {
    }

    public static b a() {
        return a;
    }

    public synchronized void a(String str) {
        if (this.d != null && this.d.contains(str)) {
            long length = (long) this.d.getString(str, "").length();
            com.huawei.hianalytics.g.b.b("BackupFileManager", "begin clear backup data! spKey:" + str);
            Editor edit = this.d.edit();
            edit.remove(str);
            edit.commit();
            this.b -= length;
        }
    }

    public synchronized void a(String str, String str2) {
        h.a(this.d, str2, (Object) str);
        this.b += (long) str.length();
    }

    public synchronized boolean b() {
        boolean z = true;
        synchronized (this) {
            if (!this.c) {
                long length = h.c(com.huawei.hianalytics.a.b.n(), "backup_event").length();
                if (this.b == 0 && length > AppSupportContentFlag.MMAPP_SUPPORT_XLS) {
                    com.huawei.hianalytics.g.b.b("BackupFileManager", "have some data in the backup file, begin clear it");
                    Editor edit = this.d.edit();
                    edit.clear();
                    edit.commit();
                }
                this.c = true;
            } else if (this.b >= 5242880) {
                z = false;
            }
        }
        return z;
    }
}
